var _table =null;
$(document).ready(function(){
    initDictRegionTable();
    $("#btn-advanced-search").click(function(){
		 refulsh();
	  });
});



var userManage = {
    getQueryCondition : function(data) {
        var param = {};

        param.datemin = $("#datemin").val();
        param.datemax = $("#datemax").val();
        param.param = $("#param").val();

        param.page = data.start;
        param.rows = data.length;


        return param;
    },
   
}

function data_edit(title,url,w,h){
	layer_show_callback(title,url,w,h,function(){
		refulsh();
	});
}
function data_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		ajaxRequestJson("deleteDictRegion",{
			"id":id
		},function(result){
			refulsh();
			layer.msg('已删除!', {icon: 6,time:1000});
		})
		
	});
}

function data_stop(obj,id){
	layer.confirm('确认要停用吗？',function(index){
		ajaxRequestJson("updateDictRegion",{
			"id":id,
			"status":0
		},function(result){
			refulsh();
			layer.msg('已停用!', {icon: 6,time:1000});
		})
		
	});
}

function data_start(obj,id){
	layer.confirm('确认要启用吗？',function(index){
		ajaxRequestJson("updateDictRegion",{
			"id":id,
			"status":1
		},function(result){
			refulsh();
			layer.msg('已启用!', {icon: 6,time:1000});
		})		
	});
}

function refulsh(){
	userManage.fuzzySearch = false;
    _table.draw();
}



function initDictRegionTable(){
	  var $table = $('#table-user');
	    _table = $table.dataTable($.extend(true,{},CONSTANT.DATA_TABLES.DEFAULT_OPTION, {
		 orderMulti: false, 
		 bFilter: false,
		 order: [],
		 renderer: "bootstrap",
		 pagingType: "simple_numbers",
		 aaSorting: [[ 1, "desc" ]],
		 bStateSave: true,
			pageLength:10,
			lengthMenu:[10,20,50,100],
			iDisplayLength: 10,
	        ajax : function(adata, callback, settings) {
	           var param = userManage.getQueryCondition(adata);
	            $.ajax({
	                    type: "post",
	                    url: "queryDictRegionPage.do",
	                    cache : false,
	                    data: param,
	                    dataType: "json",
	                    success: function(reslut) {
                            var returnData = {};
                            returnData.draw = adata.draw;
                            returnData.recordsTotal = reslut.data.total;
							returnData.recordsFiltered = reslut.data.total;
                            returnData.data = reslut.data.list;
							$("#total").text(reslut.data.total);
                            callback(returnData);
	                    },
	                    error: function(XMLHttpRequest, textStatus, errorThrown) {
	                       console.log("查询失败");
	                    }
	                });
	        },
    "columns": [
				 {"data":  function ( row, type, set ) {
	             return  '<input type="checkbox" class="iCheck" value='+row.id+'>';        
	         },"bSortable":false},
				{
					 "data": "name","bSortable": false
				},
				{
					 "data": "code","bSortable": false
				},
				{
					 "data": "level","bSortable": false
				},
				{
					 "data": "pcode","bSortable": false
				},
				{
					 "data": "p1code","bSortable": false
				},
				{
					 "data": "p2code","bSortable": false
				},
				{
					 "data": "creater","bSortable": false
				},
				{
					 "data": "gmt_create","bSortable": false
				},
				{
					 "data": "modifier","bSortable": false
				},
				{
					 "data": "gmt_modified","bSortable": false
				}
     ],
     "columnDefs": [

         {
             "targets": [20], // 目标列位置，下标从0开始
             "data": "id", // 数据列名
             "render": function(data, type, full) { // 返回自定义内容
            	 var str ="";
            	 if("1"==full.status){
            		 str ='<a style="text-decoration:none" onClick="data_stop(this,'+data+')" href="javascript:void(0);" title="禁用">';
            	 }else{
            		 str ='<a style="text-decoration:none" onClick="data_start(this,'+data+')" href="javascript:void(0);" title="启用">';
            	 }
            	 
            	 str =str+'<i class="Hui-iconfont">&#xe615;</i></a> <a title="编辑" href="javascript:void(0);" onclick="data_edit(\'管理员编辑\',\'user-add?id='+data+'\',\'700\',\'700\')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a> <a title="删除" href="javascript:void(0);" onclick="data_del(this,'+data+')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>';
            	 return str;
                
             }
         }
     ]
	 })).api();   

};  
